package paging

import (
	"github.com/gogf/gf/v2/util/gconv"
	"lot_admin_api/internal/model"
	"math"
)

// Paging 获取页面处理分页 获取偏移量
func Paging(req *model.Paging) (startNumber int, endNumber int) {
	if req.Limit == 0 {
		req.Limit = 10
	}
	if req.Page == 0 {
		req.Page = 1
	}
	// 计算偏移量
	startNumber = req.Limit * (req.Page - 1)
	// 计算当前页的条数
	//endNumber = startNumber + req.Limit
	return startNumber, req.Limit
}

// PutCount 通过每页条数和总条数来计算 总页数 返回的总页数 总条数
func PutCount(req *model.Paging, countNum int) (res *model.PutPage) {
	countPage := math.Ceil(gconv.Float64(countNum) / gconv.Float64(req.Limit))
	res = &model.PutPage{
		Limit:     req.Limit,
		Page:      req.Page,
		CountNum:  countNum,
		CountPage: countPage,
	}
	return res
}
